Skip to content

fix(core): honor Codex input limits - #38987

Open
opencode-agent[bot] wants to merge 1 commit into
v2from
codex-input-limit
Open

fix(core): honor Codex input limits#38987
opencode-agent[bot] wants to merge 1 commit into
v2from
codex-input-limit

Conversation

@opencode-agent

Copy link
Copy Markdown
Contributor

Summary

  • preserve models.dev's separate input limit through the V2 LLM route
  • overlay openai-codex model limits onto the existing OpenAI catalog only when ChatGPT OAuth is active
  • compact against input - buffer and report TUI context usage against the effective input window
  • leave direct OpenAI API-key model limits unchanged

This prevents GPT-5.6 Sol's ChatGPT subscription route from reaching output-budget exhaustion while the TUI still reports roughly 35% context usage. The canonical numbers live in anomalyco/models.dev#3754; OpenCode only selects and enforces the route-specific metadata.

@rekram1-node, the observed failure was repeated truncated patch JSON around 372K tokens. The provider returned max_output_tokens, V2 continued the malformed call, and manual compaction was the only escape. With the Codex input window applied, default auto-compaction begins at 252K (272K input minus the 20K buffer).

Verification

  • packages/core: 38 focused tests pass across model resolution, OpenAI catalog routing, and compaction
  • packages/tui: 4 context-usage tests pass
  • packages/ai: GOMAXPROCS=2 bun typecheck
  • package-wide Core/TUI typechecks remain blocked by existing generated SDK drift; no errors reference the changed limit or TUI usage code

Depends on anomalyco/models.dev#3754.

Fixes #38851
Related: #36766, #38976

Requested by: @kitlangton (Kit via Slack)

@magoz

magoz commented Jul 29, 2026

Copy link
Copy Markdown

Production evidence strongly confirms this fix's diagnosis:

  • OpenCode2 next-16302, openai/gpt-5.6-sol, ChatGPT browser OAuth
  • read-only DB backup: 19 completed auto-compactions in one affected session
  • 17/19 occurred at 33–36% displayed usage
  • preceding provider usage consistently clustered at 370k–375k tokens

That is the 372k Codex input ceiling divided by the stale 1.05M public catalog window. #32119 alone would only change the display to ~40%; the credential-specific route limit is required.

One edge worth covering: OpenAIPlugin.load() currently calls connection.resolve() and catches refresh failure as undefined. For an expired OAuth credential, a transient refresh failure sets chatgpt = false; a later successful request-time refresh may not emit ConnectionUpdated, leaving public limits until another catalog reload. Reading stored credential/method type without refresh (or retaining ChatGPT route identity on refresh failure) would keep catalog metadata independent of token validity.

@magoz

magoz commented Jul 29, 2026

Copy link
Copy Markdown

Rebased replacement: #39545. It preserves Kit’s commit authorship, resolves current v2 naming conflicts, removes the added TUI test assertion, and passes focused tests plus all 33 monorepo typechecks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants